package com.smartHire.controller.User.Order_goods;

import com.smartHire.domain.Order;
import com.smartHire.domain.Order_goods;
import com.smartHire.service.OrderService;
import com.smartHire.service.Order_goodsService;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet(name = "BackMoneyServlet", value = "/BackMoneyServlet")
public class BackMoneyServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        String id = request.getParameter("id");


        WebApplicationContext ctx = null;
        //使用框架中的方法，获取容器对象
        ServletContext sc = getServletContext();
        ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(sc);
        System.out.println("容器对象的信息========"+ctx);

        try {
            Order_goodsService order_goodsService = (Order_goodsService) ctx.getBean("order_goodsService");
            OrderService orderService = (OrderService) ctx.getBean("orderService");


            Order_goods order_goods = new Order_goods();
            order_goods.setOG_Id(Integer.parseInt(id));

            order_goods = order_goodsService.queryOrder_goodsByOG_Id(order_goods);

            Order order = new Order();
            order.setOrder_Id(order_goods.getOrder_Id());
            order = orderService.queryOrderByOrder_Id(order);

            order.setStatus(5);



            if(orderService.updateOrderStatus(order)==1)
            {
                    response.getWriter().write("OK");
            }

        }catch (Exception e)
        {
            e.printStackTrace();
        }
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
